package com.personal.sfe.util;

import cn.hutool.crypto.digest.DigestUtil;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author: 梁奔
 * @date: 2025/11/05
 */

public class CacheKeyUtils {
    private static final ObjectMapper om = new ObjectMapper()
            .setSerializationInclusion(JsonInclude.Include.NON_NULL); // 忽略 null 字段

    public static String toKey(Object obj) {
        try {
            String json = om.writeValueAsString(obj);
            return DigestUtil.md5Hex(json);
        } catch (Exception e) {
            return obj.toString();
        }
    }
}
